From 96fddfeae4b139aa4b84540a1784a5be8053454c Mon Sep 17 00:00:00 2001
From: Lee Jackson <info@arducam.com>
Date: Mon, 27 Feb 2023 08:47:23 +0800
Subject: [PATCH] dtoverlays: Add VCM option to Arducam64MP

VCM is enabled by default, but you can use 'vcm=off' to disable VCM support.

Signed-off-by: Lee Jackson <lee.jackson@arducam.com>
---
 arch/arm/boot/dts/overlays/README             |  2 +
 .../dts/overlays/arducam-64mp-overlay.dts     | 61 +++++++++----------
 arch/arm/boot/dts/overlays/arducam-64mp.dtsi  | 34 +++++++++++
 3 files changed, 65 insertions(+), 32 deletions(-)
 create mode 100644 arch/arm/boot/dts/overlays/arducam-64mp.dtsi

--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -613,6 +613,8 @@ Params: rotation                Mounting
                                 configuring the sensor (default on)
         cam0                    Adopt the default configuration for CAM0 on a
                                 Compute Module (CSI0, i2c_vc, and cam0_reg).
+        vcm                     Select lens driver state. Default is enabled,
+                                but vcm=off will disable.
 
 
 Name:   arducam-pivariety
--- a/arch/arm/boot/dts/overlays/arducam-64mp-overlay.dts
+++ b/arch/arm/boot/dts/overlays/arducam-64mp-overlay.dts
@@ -13,32 +13,7 @@
 			#size-cells = <0>;
 			status = "okay";
 
-			arducam_64mp: arducam_64mp@1a {
-				compatible = "arducam,64mp";
-				reg = <0x1a>;
-				status = "okay";
-
-				clocks = <&cam1_clk>;
-				clock-names = "xclk";
-
-				VANA-supply = <&cam1_reg>;	/* 2.8v */
-				VDIG-supply = <&cam_dummy_reg>;	/* 1.8v */
-				VDDL-supply = <&cam_dummy_reg>;	/* 1.2v */
-
-				rotation = <0>;
-				orientation = <2>;
-
-				port {
-					arducam_64mp_0: endpoint {
-						remote-endpoint = <&csi1_ep>;
-						clock-lanes = <0>;
-						data-lanes = <1 2>;
-						clock-noncontinuous;
-						link-frequencies =
-							/bits/ 64 <456000000>;
-					};
-				};
-			};
+			#include "arducam-64mp.dtsi"
 		};
 	};
 
@@ -49,8 +24,8 @@
 			brcm,media-controller;
 
 			port{
-				csi1_ep: endpoint{
-					remote-endpoint = <&arducam_64mp_0>;
+				csi_ep: endpoint{
+					remote-endpoint = <&cam_endpoint>;
 					clock-lanes = <0>;
 					data-lanes = <1 2>;
 					clock-noncontinuous;
@@ -81,14 +56,36 @@
 		};
 	};
 
+	fragment@5 {
+		target = <&cam_node>;
+		__overlay__ {
+			lens-focus = <&vcm_node>;
+		};
+	};
+
 	__overrides__ {
-		rotation = <&arducam_64mp>,"rotation:0";
-		orientation = <&arducam_64mp>,"orientation:0";
+		rotation = <&cam_node>,"rotation:0";
+		orientation = <&cam_node>,"orientation:0";
 		media-controller = <&csi>,"brcm,media-controller?";
 		cam0 = <&i2c_frag>, "target:0=",<&i2c_vc>,
 		       <&csi_frag>, "target:0=",<&csi0>,
 		       <&clk_frag>, "target:0=",<&cam0_clk>,
-		       <&arducam_64mp>, "clocks:0=",<&cam0_clk>,
-		       <&arducam_64mp>, "VANA-supply:0=",<&cam0_reg>;
+		       <&cam_node>, "clocks:0=",<&cam0_clk>,
+		       <&cam_node>, "VANA-supply:0=",<&cam0_reg>,
+		       <&vcm_node>, "VDD-supply:0=", <&cam0_reg>;
+		vcm = <&vcm_node>, "status",
+		      <0>, "=5";
 	};
 };
+
+&cam_node {
+	status = "okay";
+};
+
+&cam_endpoint {
+	remote-endpoint = <&csi_ep>;
+};
+
+&vcm_node {
+	status = "okay";
+};
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/arducam-64mp.dtsi
@@ -0,0 +1,34 @@
+// Fragment that configures a Arducam64MP
+
+cam_node: arducam_64mp@1a {
+	compatible = "arducam,64mp";
+	reg = <0x1a>;
+	status = "disabled";
+
+	clocks = <&cam1_clk>;
+	clock-names = "xclk";
+
+	VANA-supply = <&cam1_reg>;	/* 2.8v */
+	VDIG-supply = <&cam_dummy_reg>;	/* 1.8v */
+	VDDL-supply = <&cam_dummy_reg>;	/* 1.2v */
+
+	rotation = <0>;
+	orientation = <2>;
+
+	port {
+		cam_endpoint: endpoint {
+			clock-lanes = <0>;
+			data-lanes = <1 2>;
+			clock-noncontinuous;
+			link-frequencies =
+				/bits/ 64 <456000000>;
+		};
+	};
+};
+
+vcm_node: dw9817_arducam64mp@c {
+	compatible = "dongwoon,dw9817-vcm";
+	reg = <0x0c>;
+	status = "disabled";
+	VDD-supply = <&cam1_reg>;
+};
